package pl.prv.polanie.client.panels.lists;

import pl.prv.polanie.client.dialogs.CreateAcademicTitleDialog;
import pl.prv.polanie.client.dto.CSAcademicTitleDTO;
import pl.prv.polanie.client.dto.CSVAcademicTitleDTO;
import pl.prv.polanie.client.model.Cache;
import pl.prv.polanie.client.model.ViewDataProvider;
import pl.prv.polanie.client.widgets.table.TableAcademicTitles;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Widget;

public class AcademicTitlesList extends ObjectsList {

	TableAcademicTitles tableAcademicTitles= new TableAcademicTitles(this);
	
	public AcademicTitlesList() {
		
		CSAcademicTitleDTO[] ls = Cache.getAllAcademicTitles();
		//AcademicTitleDTO[] ats = Cache.getAllAcademicTitles();
		
		add(tableAcademicTitles);
		
		
		for (int i = 0; i < ls.length; i++) {
			
			CSAcademicTitleDTO cs = ls[i];
			CSVAcademicTitleDTO csv = ViewDataProvider.getCSVAcademicTitle(cs);
			
			tableAcademicTitles.addRow(cs, csv);
		}
		
		
		addRecordButton.addClickListener(new ClickListener(){
			public void onClick(Widget sender) {
				CreateAcademicTitleDialog catd = new CreateAcademicTitleDialog(AcademicTitlesList.this, null); 
				catd.center();
			}
		});
		
		removeSelectedRecordButton.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				tableAcademicTitles.removeSelectedAcademicTitleFromTable();
				removeSelectedRecordButton.setEnabled(false);
			}
		});
		
		setupButtons();
		
	}

	
	public void addCSAcademicTitle(CSAcademicTitleDTO csAcademicTitle) {
//		CSVLecturerDTO csv = ViewDataProvider.getCSVLecturer(csLecturer);
		
		tableAcademicTitles.saveOrUpdateAcademicTitleInTable(csAcademicTitle);
//		tableAcademicTitles.addRow(csLecturer, csv);
	}
	
	public void removeSelectdCSLecturer() {
		tableAcademicTitles.removeSelectedAcademicTitleFromTable();
	}
	
	
}
